package com.lk.sys.controller;

import com.lk.sys.common.vo.JsonResult;
import com.lk.sys.common.vo.Node;
import com.lk.sys.entity.SysMenu;
import com.lk.sys.service.SysMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("/menu/")
@RestController//相当于@Controller+@ResponseBody
public class SysMenuController {
    @Autowired
    private SysMenuService sysMenuService;


    @RequestMapping("doSaveObject")
    @ResponseBody
    public JsonResult doSaveObject(SysMenu entity) {
        sysMenuService.insertObject(entity);
        return new JsonResult("save ok");
    }

    /**
     * 查询sys_menu中的id，parentId，name中的内容作为zTree中的节点内容
     * @author Lukang
     * @date 2021/11/8 下午9:10
     * @return com.lk.sys.common.vo.JsonResult
     */
    //http://localhost/menu/doFindZtreeMenuNodes
    @RequestMapping("doFindZtreeMenuNodes")
    public JsonResult doFindZtreeMenuNodes() {
        List<Node> ztreeMenuNodes = sysMenuService.findZtreeMenuNodes();
        return new JsonResult(ztreeMenuNodes);
    }

    /**
     * 查询所有菜单数据
     * @author Lukang
     * @date 2021/11/4 下午9:57
     * @return com.lk.sys.common.vo.JsonResult
     */
    @RequestMapping("doFindObjects")
    public JsonResult findObjects() {
        return new JsonResult(sysMenuService.findObjects());
    }

    @RequestMapping("doDeleteObject")
    public JsonResult deleteObject(Integer id) {
        sysMenuService.deleteObject(id);
        return new JsonResult("delete ok");
    }
}
